using B.S.XZYData.Api.Wrter.Application.Command.Team;
using B.S.XZYData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.XZYData.Api.Wrter.Controllers
{
    /// <summary>
    /// 班组控制(写)
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TeamController : ControllerBase
    {
        private readonly IMediator _mediator;

        public TeamController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 添加班组
        /// </summary>
        /// <param name="command">添加班组命令</param>
        /// <returns>添加结果</returns>
        [HttpPost]
        public async Task<ApiResult<bool>> AddTeam([FromBody] AddTeamCommand command)
        {
            var result = await _mediator.Send(command);
            return result;
        }

        /// <summary>
        /// 删除班组
        /// </summary>
        /// <param name="command">删除班组命令</param>
        /// <returns>删除结果</returns>
        [HttpPost]
        public async Task<ApiResult<bool>> DeleteTeam([FromBody] DeleteTeamCommand command)
        {
            var result = await _mediator.Send(command);
            return result;
        }

        /// <summary>
        /// 编辑班组
        /// </summary>
        /// <param name="command">编辑班组命令</param>
        /// <returns>编辑结果</returns>
        [HttpPost]
        public async Task<ApiResult<bool>> UpdateTeam([FromBody] UpdateTeamCommand command)
        {
            var result = await _mediator.Send(command);
            return result;
        }

        /// <summary>
        /// 批量导入班组
        /// </summary>
        /// <param name="command">批量导入班组命令</param>
        /// <returns>导入结果</returns>
        [HttpPost]
        public async Task<ApiResult<BatchAddTeamsResult>> BatchAddTeams([FromBody] BatchAddTeamsCommand command)
        {
            var result = await _mediator.Send(command);
            return result;
        }
    }
}
